//index.js,获取应用实例
const user = require('../../utils/getUserinfo.js')
const app = getApp()
Page({
  data: {
    loginStr:'',
    memberStr:'',
    regist: '',
    member: '',
    menuList:[],
    urlList: [
      { urls:"../pages/video/video" },
      { urls:"../pages/video/video?title=video" },
      { urls:"../pages/video/video?title=video" }

    ],
    headimg: [
      {url: '../imgs/swiper/swp1.jpg'},
      {url: '../imgs/swiper/swp2.jpg'},
      {url: '../imgs/swiper/swp3.jpg'}
       
    ],

    staffA: { firstName: 'Hulk', lastName: 'Hu' },
    staffB: { firstName: 'Shang', lastName: 'You' },
    staffC: { firstName: 'Gideon', lastName: 'Lin' },
    view: 'MINA',
    message:'Hello MINA!',
    array: [1, 2, 3, 4, 5],
    templist:[],
    next:"",
    motto: 'Hello World 1234',
    userInfo:{},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo')
  },


  //事件处理函数
 bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  
  clickMe() {
    this.setData({ message: 'Hello World' })
    wx.scanCode({
      success: (res) => {
        console.log(res)
      }
    }) 
  
  },

  //获到菜单标题文字
  getMenu: function () {
    var that = this
    var p = new Promise(function (resolve, reject) {
      wx.request({
        url: 'https://www.beicho.com/get_mainMenu_course_tb.php', //接口地址 
        method: 'GET',
        header: {
          'content-type': 'application/json'
        },
        data: {},
        success: res => {
          // console.log('tb新的记录:', res.data)
          that.setData({
            menuList: res.data
          })

          //成功执行之后，返回
          resolve('success')
        }

      })

    })   //promise
    return p
  },

 onLoad: function() {
   var that = this
   that.getMenu().then(function (p) {
     // console.log(p);
     //后面可以用传过来的数据做些其他操作
     //console.log('取出来的数据:', that.data.menuList)
     //console.log('节标题:',that.data.menuList[0].sectionRec[0].sectionTitle)

   });


   if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true,
        title:''
     })
    } else if (this.data.canIUse) {
      // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        //: res => 
        success(res){
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })

    }
  },

  onShow: function () {   
    this.setData({
      loginStr: app.globalData.loginStr,
     

    })
  }
})